//
//  HXMethodVC.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/12.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXMethodVC.h"
#import "HX_Macro.h"
#import "HXDetailVideoModel.h"
#import "HXStepModel.h"
#import "HXMakeMeansTCell.h"

@interface HXMethodVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation HXMethodVC
- (void)setStep:(NSMutableArray *)step {
    _step = step;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self tableView];
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 145) style:0];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        [_tableView registerNib:[UINib nibWithNibName:@"HXMakeMeansTCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HXMakeMeansTCell"];
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    HXDetailVideoModel *videoModel = [self.step firstObject];
    return videoModel.step.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HXMakeMeansTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXMakeMeansTCell"];
    HXDetailVideoModel *videoModel = [self.step firstObject];
    [cell.imageHeader sd_setImageWithURL:[NSURL URLWithString:[videoModel.step[indexPath.row] dishes_step_image]]];
    NSString *order = [videoModel.step[indexPath.row] dishes_step_order];
    NSString *desc = [videoModel.step[indexPath.row] dishes_step_desc];
    NSString *attrString = [NSString stringWithFormat:@"%@. %@" , order, desc];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:attrString];
    NSString *str = [attrString substringWithRange:NSMakeRange(0, order.length)];
        NSRange range = [[str stringByAppendingString:[NSString stringWithFormat:@"%@", order]] rangeOfString:str];
        [string addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range];
    cell.detailLabel.attributedText = string;
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 300;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
